require('./PageParentnotice.styl');
import { Boxs,Toast, Group, NavBar } from 'saltui'
const { HBox, Box, VBox } = Boxs;
const reactMixin = require('react-mixin');
const Actions = require('./actions');
const Store = require('./store');
const WithRefresh = require('components/withrefresh');
const PendingList = require('components/pendinglist');
const ListWithNotice = WithRefresh(
    PendingList,
    (pageNum, props, success, error) => {
        Actions.fetch(pageNum, props, success, error)
    }
);
class Parentnotice extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            isEidt:false,
            selectAll:false
        };
        this.handleOnLeftClick = this.handleOnLeftClick.bind(this)
        this.handleOnRightClick = this.handleOnRightClick.bind(this);
        this.handleClickDelBtn = this.handleClickDelBtn.bind(this);
    }
    handleOnLeftClick() {
        dd.biz.navigation.close({
            onSuccess : function(result) {
            },
            onFail : function(err) {}
        })
    }
    //右侧导航按钮
    handleOnRightClick() {
        this.setState({ isEidt: !this.state.isEidt });
    }
    //删除按钮
    handleClickDelBtn() {
        let t = this;
        let cb = () => {
            t.setState({ isEidt: false })
            Toast.show({
                type: 'success',
                content: '删除成功'
            });
            let list = "ListWithNotice";
            t.refs[list].onRefresh()
        }
        Actions.deleteMsg(cb);
    }
    render() {
        return (
            <div className="parentnotice">
                <NavBar
                    isShow={false}
                    onLeftClick={this.handleOnLeftClick}
                    onRightClick={this.handleOnRightClick}
                    rightText={!this.state.isEidt ? '编辑' : '完成'}
                    title="通知公告"
                />
                {!this.state.isEidt ? null :
                    <Group.Head className="t-LH44 head">
                        <HBox vAlign="center">
                            <Box className="t-ML10">
                                {!this.state.selectAll ?
                                    <div className="circle" onClick={this.handleClickAllIcon}></div> :
                                    <Icon
                                        name="check-round"
                                        fill="#53CAC3"
                                        width={15}
                                        height={15}
                                        onClick={this.handleClickAllIcon}
                                    />
                                }
                            </Box>
                            <Box flex={2} className="t-ML10">
                                <span>全选</span>
                            </Box>
                            <Box flex={1} className="t-FAR"><div className="del-btn" onClick={this.handleClickDelBtn}>删除</div></Box>
                        </HBox>
                    </Group.Head>
                }
                <ListWithNotice
                    className="msg"
                    ref="ListWithNotice"
                    active={true}
                    isEidt={this.state.isEidt}
                    selectAll={this.state.selectAll}
                    leftSlip={false}
                />
            </div>
        );
    }

    componentWillMount() {
    }

    componentDidMount() {
    }

    componentWillReceiveProps(nextProps) {
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {
    }
}

reactMixin.onClass(Parentnotice, Reflux.connect(Store));

module.exports = Parentnotice;
